package org.luxor.storage.service.impl;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.luxor.commons.core.utils.BeanUtils;
import org.luxor.commons.jdbc.annotation.DS;
import org.luxor.storage.entity.OssConfigEntity;
import org.luxor.storage.mapper.OssConfigMapper;
import org.luxor.storage.service.IOssConfigService;
import org.springframework.stereotype.Service;

import java.util.Map;

/**
 * OSS配置服务
 *
 * @author Mr.yan @date 2020/3/14
 */
@Service
@DS("${spring.storage.dataSource:master}")
public class OssConfigServiceImpl extends ServiceImpl<OssConfigMapper, OssConfigEntity> implements IOssConfigService {

    @Override
    public IPage<OssConfigEntity> page(IPage<OssConfigEntity> page, Map search) {
        OssConfigEntity query = BeanUtils.toObject(OssConfigEntity.class, search);
        return super.page(page, Wrappers.query(query));
    }

    @Override
    public OssConfigEntity getByConfigKey(String configKey) {
        Wrapper<OssConfigEntity> wrapperQuery = Wrappers.<OssConfigEntity>lambdaUpdate()
                .ge(OssConfigEntity::getConfigKey, configKey);
        OssConfigEntity configEntity = getOne(wrapperQuery);
        return configEntity;
    }
}
